package com.adam.management.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * @projectName: adam-management-system
 * @description:
 * @author: Adam
 * @create: 2019-11-02 21:18
 **/

@Data
@TableName("T_USER")
public class UserDTO implements UserDetails, Serializable {

    private Integer id;

    private String userId;

    private String userName;

    private String password;

    private String identity;

    private String email;

    private Integer telephone;

    private Integer status;

    private String remark;

    private String gmtCreate;

    private String gmtUpdate;

    /*1.transient关键字
      2.使用静态变量(static)
      3.TableField(exist=false)*/
    @TableField(exist=false)
    private List<RoleDTO> authorities;

    public UserDTO(){}

    public UserDTO(String userName,String password,List<RoleDTO> authorities){
        this.userName = userName;
        this.password = password;
        this.authorities = authorities;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
